<?php
session_start(); 
//********************************************//
//*** CONFIGURE YOUR SERVER HERE *** START ***//
$DBH="sql.byethost27.org";
$DBU="rockedg1_rockedg";
$DBP="keelwater";
$datab="rockedg1_tank60"	;
//*** CONFIGURE YOUR SERVER HERE *** STOP ***//
//*******************************************// 
$WIZ=$_SERVER[SCRIPT_NAME];
if(!$_SESSION[RPP]) $_SESSION[RPP]=20;

$dbl=@mysql_connect($DBH,$DBU,$DBP) or die("Access denied. Check configuration."); 
  
mysql_select_db($datab,$dbl);

$TBN1= $_REQUEST['table'];
//$TBN= "tankwater";
$TBN= $TBN1;
$edit2 = $_REQUEST['edit'];
//$edit1 = base64_decode($_POST[edit]);
$edit1 = ($_POST[edit]);
 $rc=mysql_fetch_row(mysql_query("SELECT * FROM `$TBN` WHERE id='$edit2'",$dbl)); 
 $campi=mysql_list_fields($datab,$TBN,$dbl); 	
/*$campi=6;	*/
 $cols=6;
  echo("<form method='post' action='$WIZ?op=7&table=$TBN'><input type='hidden' name='edit' value='$_POST[edit]'>");
 
// $edit1 = base64_decode($_POST[edit]); 

   //print("<html><pre>");
   //print("You have submitted the following information:\n");
   //print("  campi = $campi\n");
   //print("  rc = $rc\n");
   //print("  page = $WIZ\n");
   //print("  edit1 = $edit1\n");
   //print("  edit2 = $edit2\n");
   //print("  table = $_REQUEST[table]\n");
   //print("  table = $TBN\n");
   //print("  request = $_REQUEST[op]\n");
   //print("</pre></html>\n");
 echo("<p><table>");
 for($i=0;$i<$cols;$i++) echo("<tr><td align='right'><b>".mysql_field_name($campi,$i)."</b>: </td><td>".((mysql_field_type($campi,$i)=="blob")?"<textarea cols='40' rows='4' name='".mysql_field_name($campi,$i)."'>$rc[$i]</textarea>":"<input type='text' name='".mysql_field_name($campi,$i)."' value='$rc[$i]' size='50'>")."</td></tr>");
 echo("</table></p>");

 echo("<input type='submit' value='Save'> <input type='reset' value='Reset'> <input type='button' value='Back to Edit' onClick='javascript:window.location=\"$WIZ?op=8&table=$TBN\"'></form>"); 
 
 switch($_REQUEST[op]) {
 
 case "7":
// 	 print("<html><pre>");
// 	 print("  table = $TBN\n");
//   print("  table = $_REQUEST[table]\n"); 		
$TBN= $_REQUEST['table'];	 
$campi=mysql_list_fields($datab,$TBN,$dbl);
 $cols=mysql_num_fields($campi);
 for($i=0;$i<$cols;$i++) {
  $field="$"."_POST['".mysql_field_name($campi,$i)."']";
  eval("\$field=$field;");
  $fields.="`".mysql_field_name($campi,$i)."`='" . str_replace("\$","\\\$",$field) . "', ";
 }
 eval("\$fields=\"$fields\";");
 $fields=substr($fields,0,-2);
 $qry="UPDATE `$TBN` SET $fields WHERE id='$edit2'";
 echo((mysql_query($qry,$dbl))?"Query executed":"Error executing query"); 
 // print("</pre></html>\n"); 	 
	 mysql_close($dbl); 

 break;
 case "8":
 
// $url = $_SERVER['HTTP_REFERER']; 
$url = "update_2.html";
 echo '<meta http-equiv="refresh" content="1;URL=' . $url . '">';
 mysql_close($dbl);
 break;
 }
?>
</body>
</html>
